// pages/my/message/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    skeletonLoading: true,
    loding: false,
    active: 0,
    comment_list: [
      
    ],
    like_list: [
      
    ],
    report_list: [
      
    ],
    tab: [
      "系统通知",
      "评论",
      "点赞"
    ]
  },

  /**
   * 跳转帖子
   */
  goToDetail(e) {
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '../../community/detail/index?id=' + e.currentTarget.dataset.id,
    })
  },

  /**
   * 切换
   */
  onChange(event) {
    console.log(event.detail)

    this.setData({
      active: event.detail.index
    })

    if(event.detail.index == 0){
      this.getReport()
    }else if(event.detail.index == 1){
      this.getComment()
    }else{
      this.getLike()
    }
  },

  /**
   * 获取举报
   */
  getReport: function() {
    var that = this

    wx.request({
      url: app.globalData.url + '/message_report/',
      method: "GET",
      headers: {
        'Content-Type': 'application/json'
      },
      data: {
        userID: getApp().globalData.user.userId
      },
      success: function (res) {
        console.log(res.data)

        if(res.statusCode == 500){
          that.setData({
            report_list: []
          })
        }else{
          that.setData({
            report_list: res.data
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '连接失败',
          duration: 2000,
          icon: 'error',
        })
      }
    })
  },

   /**
   * 获取评论
   */
  getComment: function() {
    var that = this

    wx.request({
      url: app.globalData.url + '/message_comment/',
      method: "GET",
      headers: {
        'Content-Type': 'application/json'
      },
      data: {
        userID: getApp().globalData.user.userId
      },
      success: function (res) {
        console.log(res.data)

        if(res.Status_code == 500){
          that.setData({
            comment_list: []
          })
        }else{
          that.setData({
            comment_list: res.data
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '连接失败',
          duration: 2000,
          icon: 'error',
        })
      }
    })
  },

   /**
   * 获取点赞
   */
  getLike: function() {
    var that = this

    wx.request({
      url: app.globalData.url + '/message_likes/',
      method: "GET",
      headers: {
        'Content-Type': 'application/json'
      },
      data: {
        userID: getApp().globalData.user.userId
      },
      success: function (res) {
        console.log(res)

        if(res.statusCode == 500){
          that.setData({
            like_list: []
          })
        }else{
          that.setData({
            like_list: res.data
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '连接失败',
          duration: 2000,
          icon: 'error',
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getReport()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})